package com.example.app_emu.core

import com.example.app_emu.core.control.DebugRPC
import com.example.lib_core.util.JsonUtils
import com.example.lib_core.util.deepCopy
import com.example.session.EndPoint
import com.example.session.IEndPoint
import java.net.InetAddress

open class EmulatorDevice(val context: IEmulatorContext, val profile: Profile) {

    open fun powerOn(){
        init()
    }

    open fun powerOff() {

    }

    open fun onReceived(payload: ByteArray, endpoint: IEndPoint) {

    }

    open fun onRPC(rpc: DebugRPC) {

    }

    fun sendTo(buffer: ByteArray){
        context.getSession().sendTo(buffer)
    }

    fun responseRPC(rpc: DebugRPC){
        val buffer = JsonUtils.gson.toJson(rpc).toByteArray()
        sendTo(buffer)
    }

    open fun init() {

    }

    class Profile{
        var sn: String = "xxxxx"
        var name: String = "emu_device"
        var address: IEndPoint = EndPoint.getLocal() //内网地址
        var ip: InetAddress = InetAddress.getByName("172.0.0.0")
    }
}